import request from '@/util/request';
import companyData from '../assets/js/company.json';


export const fetchData = () => {
    return request({
        url: './mock/table.json',
        method: 'get'
    });
};
export const fetchUserData = () => {
    return request({
        url: './mock/user.json',
        method: 'get'
    });
};

export const fetchRoleData = () => {
    return request({
        url: './mock/role.json',
        method: 'get'
    });
};

export const fetchEmployeeData = () => {
    return request({
        url: './mock/employee.json',
        method: 'get'
    });
};

export const fetchScheduleData = () => {
    return request({
        url: './mock/schedule.json',
        method: 'get'
    });
};

export const getAllOrgnize = () => {
    return request({
        url: './mock/orgnize.json',
        method: 'get'
    });
};

interface companyParams {
    name: string,
    code: string,
    tag: string,
    pageNum: number,
    pageSize: number
}
export const getCompany = (params: companyParams) => {
    const { name, code, tag, pageNum, pageSize} = params;
    console.log('companyData', companyData)

    let filteredData = companyData.filter(item => {
        return (
            (name ? item.name.includes(name) : true) &&
            (code ? item.code.includes(code) : true) &&
            (tag ? item.tag === tag : true)
        );
    });
    // 分页
    const offset = (pageNum - 1) * pageSize;
    const paginatedData = filteredData.slice(offset, offset + pageSize);

    return {
        data: paginatedData,
        total: filteredData.length
    };
}

export const getCompanyByOrg = (orgId: string) => {
    return companyData.filter(item => item.orgId === orgId);
}